﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DelonixRegiaHMSys.Core.Services;
using DelonixRegiaHMSys.Core.Models;
using DelonixRegiaHMSys.Infrastructure.Data;

namespace DelonixRegiaHMSys.UI.WebForms
{
    public partial class RoomReservationManagement : System.Web.UI.Page
    {
        string userID;
        protected void Page_Load(object sender, EventArgs e)
        {
            userID = Request.QueryString["UserID"];
            lblguestID.Text = Request.QueryString["GuestID"];
            if (!Page.IsPostBack)
            {
                string ID = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                string strid = "";
                Random rnd = new Random();
                for (int i = 0; i <= 3; i++)
                {
                    int randomint = rnd.Next(0, ID.Length - 1);
                    strid += ID.Substring(randomint, 2);
                }
                lblreservationID.Text = strid;
            }
          
        }

        protected void btnrrnext_Click(object sender, EventArgs e)
        {
            RoomReservation rr = new RoomReservation();
            rr.ReservationID = lblreservationID.Text;
            rr.GuestID = lblguestID.Text;
            rr.UserID = userID;
            rr.NumOfAdults = Convert.ToInt32(ddlnumOfAdults.SelectedValue);
            rr.NumOfChildren = Convert.ToInt32(ddlnumOfChildren.SelectedValue);
            rr.ArrivalDate = Convert.ToDateTime(tbxtime.Text);
            rr.RoomType = rblroomType.SelectedValue;
            rr.BedType = rblbedType.SelectedValue;
            rr.SmokingOrNot = rblsmokingOrNot.SelectedValue;
            rr.AddRemarks = tbxaddremarks.Text;
            rr.ReservationStatus = "N";

            var rrservice = new rrServices(new EfRoomReservationQuery());
            rrservice.AddRoomReservation(rr);
            bool SuccessOrFail = rrservice.ReservationRecordAdded(lblreservationID.Text);
            if (SuccessOrFail == true)
            {
                string queryString = "UserID=" + userID + "&ReservationID=" + rr.ReservationID;
                Server.Transfer("~/WebForms/RRandCIModule/AddRecordSuccess.aspx?" + queryString);
            }
            else
            {
                Statuslbl.Text = "Room Reservation Unsuccessful! Please ensure all fields is filled and click Next";
            }

            
        }
    }
}